package com.tjetc.view;

import com.tjetc.domain.AdoptionApplication;
import com.tjetc.domain.Animal;
import com.tjetc.domain.History;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.AdoptApplicationService;
import com.tjetc.vo.AppData;
import com.tjetc.vo.Result;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Scanner;

public class AdoptApplicationView {
    private static Scanner sc=new Scanner(System.in);
    private static AdoptApplicationService adoptApplicationService= ClientProxy.getProxyInstance(AdoptApplicationService.class);
    public void start() {
        while (true){
            System.out.println("1.可领养动物列表");
            System.out.println("2.根据动物 ID 查询详情");
            System.out.println("3.提交领养申请");
            System.out.println("4.我的领养申请记录");
            System.out.println("5.我的领养历史");
            System.out.println("0.返回上一级");
            System.out.println("请输入你的选择0~5");
            int i=sc.nextInt();
            switch (i){
                case 1:
                    list();
                    break;
                case 2:
                    getById();
                    break;
                case 3:
                    addApplication();
                    break;
                case 4:
                    listApplication();
                case 5:
                    listHistory();
                    break;
                case 0:
                    return;
                default:
                    System.out.println("请重新输入");
            }

        }
    }

    private void listHistory() {
        Result result=adoptApplicationService.listHistory(AppData.adopter.getId());
        List<History> list=(List<History>) result.getData();
        if (list.size()>0){
            for (History history : list) {
                System.out.println(history);
            }
        }else {
            System.out.println("你还没有领养成功");
        }
    }

    private void listApplication() {
        Result result=adoptApplicationService.listApplication(AppData.adopter.getId());
        List<AdoptionApplication> list=(List<AdoptionApplication>) result.getData();
        if (list.size()>0) {
            for (AdoptionApplication list1 : list) {
                System.out.println(list1);
            }
        }else {
            System.out.println("你还没有申请过");
        }

    }

    private void addApplication() {
        list();
        System.out.println("请输入宠物id");
        int id= sc.nextInt();
        Result result=adoptApplicationService.addApplication(new AdoptionApplication().setAdopterId(AppData.adopter.getId()).setAnimalId(id).setApplicationTime(LocalDateTime.now()).setStatus(0));
        System.out.println(result.getMsg());
    }

    private void getById() {
        list();
        System.out.println("请输入id");
        int id= sc.nextInt();
        Result result=adoptApplicationService.getById(id);
        System.out.println(result.getData());
    }

    private void list() {
        Result result=adoptApplicationService.list();
        List<Animal> list=(List<Animal>) result.getData();
        if (list.size()>0) {
            for (Animal list1 : list) {
                System.out.println(list1);
            }
        }else {
            System.out.println("没有宠物可以领养");
        }
    }
}
